package box.tuson.com.tusonbox;
import android.hardware.*;
import android.os.*;
import android.support.v7.app.*;
import android.view.*;
import android.view.View.*;
import android.hardware.Camera.*;
import android.widget.*;
import android.support.v4.widget.*;

public class sdt extends AppCompatActivity
{
	Camera camera;
	boolean is_flashlight;
	String flashMode;
	private Button btn;
	private ImageView image;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sdt);
		image =  (ImageView) findViewById(R.id.sdtImageView1);
		findViewById(R.id.sdtButton1).setOnClickListener(new OnClickListener() {

				private Camera.Parameters parameters;

				@Override
				public void onClick(View arg0) {
					is_flashlight = !is_flashlight;
					if (camera == null) {
						camera = Camera.open();
					}
					if (is_flashlight) {
						btn = (Button) findViewById(R.id.sdtButton1);
						btn.setText("关闭手电筒");
						image.setBackgroundResource(R.drawable.image_4);
						flashMode = Camera.Parameters.FLASH_MODE_TORCH;
					} else {
						btn = (Button) findViewById(R.id.sdtButton1);
						btn.setText("开启手电筒");
						image.setBackgroundResource(R.drawable.image_3);
						flashMode = Camera.Parameters.FLASH_MODE_OFF;
					}
					Parameters parameters = camera.getParameters();
					parameters.setFlashMode(flashMode);
					camera.setParameters(parameters);
				}
			});
	}
}
